//
//  NoticeTableView.m
//  wtshoppingcite
//
//  Created by TW on 15-1-12.
//  Copyright (c) 2015年 TW. All rights reserved.
//

#import "NoticeTableView.h"
#import "CommunityModel.h"

@implementation NoticeTableView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if(self){
        self.backgroundView = nil;
        self.backgroundColor = [UIColor whiteColor];
        self.dataSource = self;
        self.delegate = self;
        self.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"not_background"]];
        self.separatorColor = [UIColor clearColor];
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return self;
}


#pragma mark uitableView -delegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.data.count;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

#pragma mark uitableView - DataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NoticeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"noticeCell"];
    if (cell == nil) {
        cell = [[NoticeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"noticeCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    cell.communityModel = [self.data objectAtIndex:indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CommunityModel *communityModel = self.data[indexPath.row];
    
    NSString* content = communityModel.outline;
    NSString* title = communityModel.title;
    NSString* time = communityModel.createTime;
    CGFloat titleHeight = [UIUtility getHeightOfString:title withFont:[UIFont systemFontOfSize:16.0f] withWidth:300];
    CGFloat timeHeight = [UIUtility getHeightOfString:time withFont:[UIFont systemFontOfSize:12.0f] withWidth:300];
    CGFloat contentHeight = [UIUtility getHeightOfString:content withFont:[UIFont systemFontOfSize:14.0f] withWidth:300];
    if(contentHeight>100){
        contentHeight = 90;
    }
    float h = titleHeight + timeHeight +contentHeight + 50;
    return h;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(self.eventsDelegate!= nil  && [self.eventsDelegate respondsToSelector:@selector(basetableView:didSelectRowAtIndexPath:)]){
        [self.eventsDelegate basetableView:self didSelectRowAtIndexPath:indexPath];
    }
    
}



@end
